<?php
namespace Commnet\Api;
use PhalApi\Api;
use PhalApi\Cache;
use Commnet\Domain\Commnet as CommnetDomain;

/**
 * 评论接口
 * @author: dogstar <chanzonghuang@gmail.com> 2014-10-04
 */
class Commnet extends Api {
    public function getRules() {
        return array(
            'add' => array(
                'name'  => array('name' => 'name', 'default' => '默认', 'desc' => '分类名'),
                'title'  => array('name' => 'title', 'default' => 'title', 'desc' => '标题'),
                'content'  => array('name' => 'content', 'default' => 'content', 'desc' => '内容'),
            ),
            'get' => array(
                'name'  => array('name' => 'name', 'default' => '默认', 'desc' => '分类名'),
            ),
            'getRandom' => array(
                'name'  => array('name' => 'name', 'default' => '默认', 'desc' => '分类名'),
            ),
        );
    }

    /**
     * 新增评论
     * @desc 新增评论
     */
    public function add() {
        //新增一条评论, 并统计分类总数, 且标题和内容相同时,排重
        $data = array(
            'name' => $this->name,
            'title' => $this->title,
            'content' => $this->content,
        );

        $Domain = new CommnetDomain();
        return $Domain->addCommnet($data);
    }

    /**
     * 获取评论
     * @desc 按顺序获取评论
     */
    public function get() {
        //分类名
        $name = $this->name;
        $Domain = new CommnetDomain();
        return $Domain->getCommnet($name);
    }

}
